<?php

$sms_lang = array(
    'user_id' => '用户ID',

);//该项如果更改通道需要修改
$config = array(
    'user_id' => array(
        'INPUT_TYPE' => '0',
        'VALUES' => ''
    )
);
/* 模块的基本信息 */
if (isset($read_modules) && $read_modules == true) {
    $module['class_name'] = 'LANZ';
    /* 名称 */
    $module['name'] = "浪驰（LANZ）商务短信快车";
    $module['lang'] = $sms_lang;
    $module['config'] = $config;
    $module['server_url'] = 'http://www.lanz.net.cn/LANZGateway/DirectSendSMSs.asp';

    return $module;
}

// 企信通短信平台
require_once SITE_PATH . "system/libs/sms.php";  //引入接口
require_once SITE_PATH . "system/sms/QXT/transport.php";
require_once SITE_PATH . "system/sms/QXT/XmlBase.php";

class LANZ_sms implements sms
{
    public $sms;
    public $message = "";

    private $statusStr = array(
        "1000" => "当前用户已经登录",
        "1001" => "当前用户没有登录",
        "1002" => "登录被拒绝",
        "2001" => "短信发送失败",
        "2002" => "短信库存不足",
        "2003" => "存在无效的手机号码",
        "2004" => "短信内容包含禁用词语",
        "3001" => "没有要接收的短信",
        "3002" => "没有要接收的回复状态",
        "9001" => "JobID参数不符合要求",
        "9002" => "SendDate或SendTime参数不是有效日期",
        "9003" => "短信内容长度超过300或为空",
        "9004" => "参数不符合要求",
        "9099" => "其它系统错误"
    );

    public function __construct($smsInfo = '')
    {
        if (!empty($smsInfo)) {
            $this->sms = $smsInfo;
        }
    }

    public function sendSMS($mobile_number, $content)
    {
        if (is_array($mobile_number)) {
            $mobile_number = implode(";", $mobile_number);
        }
        $sms = new transport();
        //userID=879182 username= ruiqi123 password=ANJD6Y
        $params = array(
            "UserID" => $this->sms['config']['user_id'],
            "Account" => $this->sms['user_name'],
            "Password" => $this->sms['password'],
            "SMSType" => '1',
            "Phones" => $mobile_number,
            "Content" => $content,
            "sendDate" => '',
            "sendtime" => ''
        );

        $result = $sms->request($this->sms['server_url'], $params, 'GET');
        $smsStatus = toArray($result['body'], 'LANZ_ROOT');

        $code = $smsStatus['ErrorNum'][0];

        if ($code == '0') {
            $result['status'] = 1;
        } else {
            $result['status'] = 0;
            $result['msg'] = $this->statusStr[$code];
        }
        return $result;
    }

    private function check_error($response){
        if(isset($response['ErrorNum'][0]) && $response['ErrorNum'][0] != '0'){
             exit($this->statusStr[$response['ErrorNum'][0]]);
        }
    }

    public function getSmsInfo()
    {

        return "浪驰（LANZ）商务短信快车";

    }

    public function check_fee()
    {
        $sms = new transport();

        $params = array(
            "UserID" => $this->sms['config']['user_id'],
            "Account" => $this->sms['user_name'],
            "Password" => $this->sms['password']
        );
        $url = "http://www.lanz.net.cn/LANZGateway/Login.asp";
        $result = $sms->request($url, $params, 'GET');
        unset($params);
        $result = toArray($result['body'], "LANZ_ROOT");
        $this->check_error($result);
        $action_id = $result['ActiveID'][0];
        $url = "http://www.lanz.net.cn/LANZGateway/GetSMSStock.asp";
        $params = array('ActiveID' => $action_id);
        $result = $sms->request($url, $params, 'GET');
        $this->check_error($result);
        unset($params);
        $result = toArray($result['body'], "LANZ_ROOT");
        $this->check_error($result);
        $str = "浪驰（LANZ）商务短信快车，剩余：" . $result['Stock']['0'] . "条";

        $url = "http://www.lanz.net.cn/LANZGateway/Logoff.asp";
        $params = array('ActiveID' => $action_id);
        $sms->request($url, $params, 'GET');
        return $str;

    }
}

?>